package kafka

import (
	"github.com/gogf/gf/container/gmap"
)

var (
	instances   = gmap.NewStrAnyMap(true)
	DefaultName = "default"
)

func Instance(name ...string) *KafkaClient {
	key := DefaultName
	if len(name) > 0 && name[0] != "" {
		key = "kafka.config." + name[0]
	} else {
		key = "kafka.config." + key
	}
	return instances.GetOrSetFuncLock(key, func() interface{} {
		return NewClient(key)
	}).(*KafkaClient)
}

// 客户端示例
func Client(name ...string) *KafkaClient {
	return Instance(name...)
}